@import 'assets/stylesheets/gutenberg-base-styles';
@import '../../mixins.scss';
@import '../../variables.scss';

.style-preview {
	height: auto;
	display: flex;
	flex-direction: column;

	@include break-small {
		// Full height comes from viewport heigh - header - some space for the preview's box-shadow (20px)
		height: calc( 100vh - #{$onboarding-header-height + 20px} );
	}
}

.style-preview__header {
	position: relative;
	display: flex; // IE11 fix
	justify-content: space-between;
	align-items: center;
	@include onboarding-heading-padding;
}

.style-preview__viewport-select {
	@include break-small {
		display: block;
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate( -50%, -50% );
	}
}

@supports ( display: grid ) {
	.style-preview__header {
		display: grid;
		grid-template-areas: 'title viewport-select actions';
		column-gap: 1em;
	}

	.style-preview__titles {
		grid-area: title;
	}

	.style-preview__viewport-select {
		grid-area: viewport-select;
		position: initial;
		top: 0;
		left: 0;
		transform: none;
	}

	.style-preview__actions {
		grid-area: actions;
		justify-self: end;
	}
}

.style-preview__content {
	padding-bottom: $onboarding-footer-height + 28px;
	display: flex; // needed for IE

	@include break-small {
		padding-bottom: 0;
		height: 100%; // needed for IE
	}
}

.style-preview__font-options {
	float: left;
	width: 100%;

	@include break-small {
		width: 163px;
	}
}

.style-preview__font-options-desktop {
	display: none;

	@include break-small {
		display: block;
	}
}

.style-preview__font-options-mobile {
	display: block;
	margin-bottom: 28px;

	svg {
		margin-left: 0.2em;
		vertical-align: middle;
		transition: transform 100ms ease-in-out;
	}

	.is-open svg {
		transform: rotate( 180deg );
	}

	@include break-small {
		display: none;
	}
}

.style-preview__font-options-mobile-options {
	display: none;
	border: 1px solid var( --studio-gray-10 );
	border-top: none;

	&.is-open {
		display: block;
	}
}

@supports ( display: grid ) {
	.style-preview__content {
		display: grid;
		width: 100%;
		grid-template-areas: 'fonts' 'preview';
		grid-template-columns: auto;
		grid-template-rows: auto 240px;

		@include onboarding-break-mobile-tall {
			grid-template-rows: auto 340px;
		}

		@include break-small {
			column-gap: 50px;
			flex: 1;
			grid-template-areas: 'fonts preview';
			grid-template-columns: 163px auto;
			grid-template-rows: auto;
		}

		@include break-medium {
			column-gap: 100px;
		}
	}

	.style-preview__font-options {
		width: 100%;

		@include break-small {
			width: auto;
		}
	}
}

.style-preview__font-option {
	min-height: 3.4em;
	box-shadow: inset 0 0 0 1px var( --studio-gray-10 );
	display: block;
	width: 100%;
	position: relative;
	// for IE, see https://github.com/Automattic/wp-calypso/pull/40881#issuecomment-610836378
	vertical-align: top;

	&.style-preview__font-option-mobile {
		box-shadow: none;
	}

	&.is-selected-dropdown-option span {
		font-weight: 600;
		text-decoration: underline;
	}

	+ .style-preview__font-option {
		margin-top: 8px;

		&.style-preview__font-option-mobile {
			margin-top: 0;
		}

		@include break-small {
			margin-top: 1em;
		}
	}

	.style-preview__font-option-contents {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate( -50%, -50% );
		width: 100%;
	}

	&.is-selected {
		// override default focus and hover styles for selected-fonts buttons
		// `!important` is used because there are default `focus` and `hover` styles with high specificities.
		color: var( --studio-blue-40 ) !important;
		box-shadow: inset 0 0 0 1px var( --studio-blue-40 ) !important;
	}
}

.style-preview__font-option {
	display: flex;
}

.style-preview__preview {
	float: left;
	width: 100%;
	max-width: 100%;
	margin-bottom: 28px;
	padding-left: 0;

	@include break-small {
		width: calc( 100% - 163px );
		height: 100%;
		margin: 0 auto;
		padding-left: 100px;

		&.is-viewport-tablet {
			max-width: 1024px;
		}

		&.is-viewport-mobile {
			max-width: 351px;
		}
	}
}

@supports ( display: grid ) {
	.style-preview__preview {
		grid-area: preview;
		width: 100%;
		padding-left: 0;

		&.is-viewport-tablet {
			max-width: 1024px;
		}

		&.is-viewport-mobile {
			max-width: 351px;
		}
	}
}

.style-preview__preview-wrapper {
	background: var( --studio-white );
	box-shadow: 0 0 0 1px var( --studio-gray-5 );
	border-radius: 2px;
	overflow: hidden;
	position: relative;

	width: 100%;
	margin: 0 auto;
	height: 100%;
	@include break-small {
		min-height: 400px;
	}

	@include break-wide {
		min-height: 600px;
	}

	.is-viewport-mobile &,
	.is-viewport-tablet & {
		height: 0;
		box-sizing: border-box;
		border: 13px solid var( --studio-white );

		box-shadow: 0 0 0 1px var( --studio-gray-5 ), 0 4px 14px rgba( 0, 0, 0, 0.14 ),
			inset 0 0 0 1px var( --studio-gray-5 );
		border-radius: 31px;
	}

	.is-viewport-tablet & {
		padding-top: 768 / 1024 * 100%;
	}

	.is-viewport-mobile & {
		padding-top: 691 / 351 * 100%;
	}

	@include break-small {
		box-shadow: 0 0 0 1px var( --studio-gray-5 ), 0 4px 14px rgba( 0, 0, 0, 0.1 );
	}
}

$gutenboarding-style-preview-bar-height: 30px;
$gutenboarding-style-preview-bar-height-mobile: 15px;

// This and the following dot class render the browser chrome
.style-preview__preview-bar {
	position: absolute;
	top: 0;
	width: 100%;
	height: $gutenboarding-style-preview-bar-height-mobile;
	background: var( --studio-white );
	border-bottom: 1px solid var( --studio-gray-5 );
	display: flex;
	flex-direction: row;
	align-items: center;
	padding: 5px;

	@include break-small {
		padding: 10px;
		height: $gutenboarding-style-preview-bar-height;
	}
}

.style-preview__preview-bar-dot {
	background: var( --studio-gray-5 );
	width: 3px;
	height: 3px;
	border-radius: 50%;
	margin: 0 2px;

	@include break-small {
		width: 6px;
		height: 6px;
	}
}

.style-preview__viewport-select {
	display: none;

	@include break-large {
		display: flex;
		justify-content: center;
	}
}

.style-preview__viewport-select-button {
	color: var( --studio-gray-10 );

	// Need the extra specificity here to override core
	&.components-button {
		color: var( --studio-gray-10 );
		height: auto;
		padding: 4px;

		&.is-selected,
		&:hover,
		&:focus {
			color: var( --studio-black );
		}

		svg {
			fill: none;
		}
	}
}

// Remove focus styling from clicking a button
// Keep keyboard-focused focus style
html:not( .accessible-focus ) .style-preview__viewport-select-button:focus:not( :disabled ) {
	box-shadow: none;
}

.style-preview__iframe {
	$scale-factor: 0.7;
	// Extra specificify to override editor iframe styles
	.style-preview__preview & {
		width: 100% / $scale-factor;
		height: 100% / $scale-factor;
	}

	position: absolute;
	top: 0;

	transform: scale( $scale-factor );
	transform-origin: 0 0;

	.is-viewport-desktop & {
		top: $gutenboarding-style-preview-bar-height-mobile;
		height: calc(
			#{100% / $scale-factor} - #{$gutenboarding-style-preview-bar-height-mobile / $scale-factor}
		);
		@include break-small {
			top: $gutenboarding-style-preview-bar-height;
			height: calc(
				#{100% / $scale-factor} - #{$gutenboarding-style-preview-bar-height / $scale-factor}
			);
		}
	}
}
